import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.io.IOException;

/**
 * Created by John on 2018/1/11 18:24.
 */
public class HdfsCommonOper {

    public static void main(String[] args) {
        if(args.length < 1){
            System.out.println("Usage: HdfsCommonOper <path>");
            System.exit(1);
        }
        System.out.println("start hdfs oper!");

        try {
            FileSystem fileSystem = FileSystem.newInstance(new Configuration());
            FileStatus[] fileStatuses = fileSystem.listStatus(new Path(args[0]));
            if(fileStatuses.length > 0){
                for(FileStatus fs: fileStatuses){
                    System.out.println(fs.getPath().getName() + "\tspace size:"  + fs.getLen());
                }
            }
            fileSystem.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        System.out.println("finish hdfs oper!");
    }

    public static int add(int a,int b){
        return a+b;
    }
}

